package com.ruoyi.web.controller.trade;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.trade.domain.CostGrid;
import com.ruoyi.trade.service.ICostGridService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 成本网格Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/trade/costGrid")
public class CostGridController extends BaseController
{
    @Autowired
    private ICostGridService costGridService;

    /**
     * 查询成本网格列表
     */
    @PreAuthorize("@ss.hasPermi('trade:costGrid:list')")
    @GetMapping("/list")
    public TableDataInfo list(CostGrid costGrid)
    {
        startPage();
        List<CostGrid> list = costGridService.selectCostGridList(costGrid);
        return getDataTable(list);
    }

    /**
     * 导出成本网格列表
     */
    @PreAuthorize("@ss.hasPermi('trade:costGrid:export')")
    @Log(title = "成本网格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CostGrid costGrid)
    {
        List<CostGrid> list = costGridService.selectCostGridList(costGrid);
        ExcelUtil<CostGrid> util = new ExcelUtil<CostGrid>(CostGrid.class);
        util.exportExcel(response, list, "成本网格数据");
    }

    /**
     * 获取成本网格详细信息
     */
    @PreAuthorize("@ss.hasPermi('trade:costGrid:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(costGridService.selectCostGridById(id));
    }

    /**
     * 新增成本网格
     */
    @PreAuthorize("@ss.hasPermi('trade:costGrid:add')")
    @Log(title = "成本网格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CostGrid costGrid)
    {
        return toAjax(costGridService.insertCostGrid(costGrid));
    }

    /**
     * 修改成本网格
     */
    @PreAuthorize("@ss.hasPermi('trade:costGrid:edit')")
    @Log(title = "成本网格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CostGrid costGrid)
    {
        return toAjax(costGridService.updateCostGrid(costGrid));
    }

    /**
     * 删除成本网格
     */
    @PreAuthorize("@ss.hasPermi('trade:costGrid:remove')")
    @Log(title = "成本网格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(costGridService.deleteCostGridByIds(ids));
    }
}
